//
//  PasswordCheckView.m
//  gpos_app
//
//  Created by 崔航飞 on 2018/8/29.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "PasswordCheckView.h"
#import "Masonry.h"
#import "LockController.h"
#import "LockViews.h"
#import "UIView+Extension.h"

#define KSCREENW [UIScreen mainScreen].bounds.size.width

#define KSCREENH [UIScreen mainScreen].bounds.size.height

@interface PasswordCheckView ()<LockViewsDelegate>

@property (strong, nonatomic)  UIButton *forgetBtn;
@property (strong ,nonatomic)  UIView *naviViewl;
@property (strong ,nonatomic)  UILabel *naviLab;
@property (strong ,nonatomic)  UIView *lineV;
@property(weak,nonatomic)LockViews *lockview;

@end
@implementation PasswordCheckView
+ (instancetype)sharedInstance {
    static dispatch_once_t onceToken;
    static id sharedInstance = nil;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[self alloc] initWithFrame:[UIScreen mainScreen].bounds];
    });
    return sharedInstance;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor=[UIColor whiteColor];
        [self addSubview:self.forgetBtn];
        [self addSubview:self.naviViewl];
        [self addSubview:self.naviLab];
        [self addSubview:self.lineV];
        [self setNeedsUpdateConstraints];
        LockViews *lockview = [[LockViews alloc]init];
        lockview.backgroundColor = [UIColor clearColor];
        lockview.width = 300;
        lockview.height = 300;
        lockview.x = (KSCREENW - lockview.width) * 0.5;
        lockview.y = 150;
        self.lockview = lockview;
        lockview.delegate = self;
        [self addSubview:lockview];
       
        self.lockview.delegate = self;
        [self createLockPoints];
    }
    return self;
}
-(void)createLockPoints{

    
    [_naviViewl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.height.equalTo(@(kNavbarHeight));
    }];
    
    [_lineV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.naviViewl.mas_bottom).offset(-0.5);
        make.left.equalTo(self.naviViewl.mas_left);
        make.right.equalTo(self.naviViewl.mas_right);
        make.height.equalTo(@(0.5));
    }];
    
    [_naviLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.lineV.mas_bottom).offset(-15);
        make.left.equalTo(self.naviViewl.mas_left);
        make.right.equalTo(self.naviViewl.mas_right);
        make.height.equalTo(@(20));
    }];
    
//    [_forgetBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.mas_top).offset(200);
//        make.left.equalTo(self.mas_left).offset(30);
//        make.width.equalTo(@(150));
//        make.height.equalTo(@70);
//    }];

}

//- (UIButton *)forgetBtn {
//
//    if (!_forgetBtn) {
//        _forgetBtn = [UIButton buttonWithType:UIButtonTypeSystem];
//        [_forgetBtn setTitle:@"忘记手势密码？" forState:0];
//        _forgetBtn.titleLabel.font = [UIFont systemFontOfSize:17];
//        [_forgetBtn setTitleColor:[UIColor whiteColor] forState:0];
//        [_forgetBtn addTarget:self action:@selector(backShow) forControlEvents:UIControlEventTouchUpInside];
//    }
//    return _forgetBtn;
//
//}
-(UIView *)naviViewl{
    
    if (!_naviViewl) {
        _naviViewl=[[UIView alloc] init];
        _naviViewl.backgroundColor=[UIColor whiteColor];
    }
    return _naviViewl;
    
}
-(UIView *)lineV{
    
    if (!_lineV) {
        _lineV=[[UIView alloc] init];
        _lineV.backgroundColor=[UIColor colorWithWhite:0.8 alpha:1];
    }
    return _lineV;
    
}
-(UILabel *)naviLab{
    
    if (!_naviLab) {
        _naviLab=[[UILabel alloc] init];
        _naviLab.text=@"手势密码";
        _naviLab.textAlignment=NSTextAlignmentCenter;
        _naviLab.font=[UIFont systemFontOfSize:17];
    }
    return _naviLab;
    
}
-(void)dismissView{
    
    [self resignKeyWindow];
    self.hidden = YES;
    
}

- (void)show {
    
    self.windowLevel = UIWindowLevelAlert;
    [self makeKeyWindow];
    self.hidden = NO;
}

@end
